import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';

import '../../app_views.dart';

/// 命理分析页面 - Analysis page
/// 
/// 提供各种命理分析功能，包括八字排盘、紫微斗数、奇门遁甲等
/// Provides various numerology analysis functions including BaZi, ZiWei, QiMen, etc.
class AnalysisView extends GetView<AnalysisLogic> {
  const AnalysisView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.background,
      appBar: AppBar(
        backgroundColor: AppColors.backgroundCard,
        elevation: 0,
        title: Text(
          '命理分析',
          style: GoogleFonts.notoSansSc(
            fontSize: 20,
            fontWeight: FontWeight.w700,
            color: AppColors.textPrimary,
          ),
        ),
        centerTitle: true,
      ),
      body: Obx(() {
        final analysisItems = controller.state.value.analysisItems;
        
        return SingleChildScrollView(
          padding: const EdgeInsets.all(20),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              // 页面标题和描述 - Page title and description
              Text(
                '专业命理分析',
                style: GoogleFonts.notoSansSc(
                  fontSize: 24,
                  fontWeight: FontWeight.w700,
                  color: AppColors.textPrimary,
                ),
              ),
              const SizedBox(height: 8),
              Text(
                '基于传统命理学，为您提供专业的人生指导',
                style: GoogleFonts.notoSansSc(
                  fontSize: 14,
                  color: AppColors.textSecondary,
                ),
              ),
              const SizedBox(height: 24),
              
              // 分析功能网格 - Analysis features grid
              GridView.builder(
                shrinkWrap: true,
                physics: const NeverScrollableScrollPhysics(),
                gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 2,
                  childAspectRatio: 1.1,
                  crossAxisSpacing: 16,
                  mainAxisSpacing: 16,
                ),
                itemCount: analysisItems.length,
                itemBuilder: (context, index) {
                  final item = analysisItems[index];
                  return _buildAnalysisCard(item);
                },
              ),
            ],
          ),
        );
      }),
    );
  }

  /// 构建分析功能卡片 - Build analysis feature card
  Widget _buildAnalysisCard(String item) {
    return InkWell(
      onTap: () => _showComingSoon(item),
      borderRadius: BorderRadius.circular(24),
      child: Container(
        decoration: BoxDecoration(
          gradient: LinearGradient(
            begin: Alignment.topLeft,
            end: Alignment.bottomRight,
            colors: AppColors.gradientWarm,
          ),
          borderRadius: BorderRadius.circular(24),
          border: Border.all(
            color: AppColors.primary.withOpacity(0.2),
            width: 1,
          ),
          boxShadow: [
            BoxShadow(
              color: AppColors.shadow,
              blurRadius: 16,
              offset: const Offset(0, 8),
            ),
          ],
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              width: 64,
              height: 64,
              decoration: BoxDecoration(
                color: AppColors.textOnPrimary.withOpacity(0.2),
                borderRadius: BorderRadius.circular(20),
                border: Border.all(
                  color: AppColors.textOnPrimary.withOpacity(0.3),
                  width: 1,
                ),
              ),
              child: Icon(
                _getIconForAnalysis(item),
                size: 32,
                color: AppColors.textOnPrimary,
              ),
            ),
            const SizedBox(height: 16),
            Text(
              item,
              textAlign: TextAlign.center,
              style: GoogleFonts.notoSansSc(
                fontSize: 14,
                fontWeight: FontWeight.w600,
                color: AppColors.textOnPrimary,
              ),
            ),
          ],
        ),
      ),
    );
  }

  /// 获取分析功能图标 - Get analysis feature icon
  IconData _getIconForAnalysis(String analysis) {
    switch (analysis) {
      case '八字排盘':
        return Icons.calendar_view_day_rounded;
      case '紫微斗数':
        return Icons.star_rounded;
      case '奇门遁甲':
        return Icons.explore_rounded;
      case '六爻占卜':
        return Icons.casino_rounded;
      case '梅花易数':
        return Icons.local_florist_rounded;
      case '风水分析':
        return Icons.home_rounded;
      default:
        return Icons.psychology_rounded;
    }
  }

  /// 显示功能建设中提示 - Show coming soon dialog
  void _showComingSoon(String feature) {
    Get.dialog(
      AlertDialog(
        backgroundColor: AppColors.backgroundCard,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(24),
        ),
        title: Text(
          '功能建设中',
          style: GoogleFonts.notoSansSc(
            fontSize: 20,
            fontWeight: FontWeight.w700,
            color: AppColors.textPrimary,
          ),
        ),
        content: Text(
          '$feature 功能正在开发中，敬请期待。',
          style: GoogleFonts.notoSansSc(
            fontSize: 16,
            color: AppColors.textSecondary,
          ),
        ),
        actions: [
          TextButton(
            onPressed: Get.back,
            style: TextButton.styleFrom(
              backgroundColor: AppColors.primary.withOpacity(0.1),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(16),
              ),
            ),
            child: Text(
              '知道了',
              style: GoogleFonts.notoSansSc(
                fontSize: 16,
                fontWeight: FontWeight.w600,
                color: AppColors.primary,
              ),
            ),
          ),
        ],
      ),
    );
  }
}